﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.Web;
using System.IO;
using JumbotCms.Common;
namespace JumbotCms.WebFile.Admin
{
    public partial class _mail_system : JumbotCms.API.AdminCenter
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Admin_Load("0000", "html");
            if (!Page.IsPostBack)
            {
                string strXmlFile = HttpContext.Current.Server.MapPath("~/_data/config/mail.config");
                Jumbot.DataOper.XmlControl XmlTool = new Jumbot.DataOper.XmlControl(strXmlFile);
                string _SystemAddress = XmlTool.GetText("Mails/System/Address");
                string _SystemNickName = XmlTool.GetText("Mails/System/NickName");
                string _SystemPassword = XmlTool.GetText("Mails/System/Password");
                string _SystemMailHost = XmlTool.GetText("Mails/System/MailHost");
                this.txtSystemAddress.Text = _SystemAddress;
                this.txtSystemNickName.Text = _SystemNickName;
                //this.txtSystemPassword.Text = _SystemPassword;这个没用
                this.txtSystemPassword.Attributes.Add("value", _SystemPassword);   
                this.txtSystemMailHost.Text = _SystemMailHost;
                XmlTool.Dispose();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string _To = "4259024@qq.com";
            string _Title = "邮箱配置测试邮件(请删)";
            string _Body = "邮件测试！<br>" +
                site.Name + "成功配置了系统邮箱！！！<br>" +
                "<a href=\"" + site.Url + site.Dir + "\" target=\"_blank\">" + site.Name +
                "</a>";
            string _MailFrom = this.txtSystemAddress.Text;
            string _MailFromName = this.txtSystemNickName.Text;
            string _MailPwd = this.txtSystemPassword.Text;
            string _MailFromHost = this.txtSystemMailHost.Text;
            if (Jumbot.Common.Mail.Send(_To, _Title, _Body, true, _MailFrom, _MailFromName, _MailPwd, _MailFromHost))
            {
                string strXmlFile = HttpContext.Current.Server.MapPath("~/_data/config/mail.config");
                Jumbot.DataOper.XmlControl XmlTool = new Jumbot.DataOper.XmlControl(strXmlFile);
                XmlTool.Update("Mails/System/Address", _MailFrom);
                XmlTool.Update("Mails/System/NickName", _MailFromName);
                XmlTool.Update("Mails/System/Password", _MailPwd);
                XmlTool.Update("Mails/System/MailHost", _MailFromHost);
                XmlTool.Save();
                XmlTool.Dispose();
                FinalMessage("保存成功!", "system.aspx", 0);
            }
            else
                FinalMessage("配置有误:不是所有的信箱都可以", "system.aspx", 0);
        }
    }
}
